﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MiniWeb.M.Code;
using MiniWeb.Task;
using WFramework.Utility;

namespace MiniWeb.M.Controllers
{
    public class UserCenterController : UserBaseController
    {
        //
        // GET: /UserCenter/
        public readonly OrderAddressTask _OrderAddressTask = new OrderAddressTask();
        public readonly AccountsInfoTask _AccountsInfoTask = new AccountsInfoTask();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Address()
        {
            var list = _OrderAddressTask.GetByAccount(WebFormsAuthService.GetCurrentAccount());
            return View(list);
        }

        public ActionResult ChangePwd()
        {
            return View();
        }
        [HttpPost]
        public ActionResult ChangePwd(string pwd, string cpwd, string cpw1)
        {
            if (string.IsNullOrEmpty(cpwd) || string.IsNullOrEmpty(pwd))
            {
                return AlertMsg("密码不能为空！", Request.UrlReferrer.ToString());
            }
            if (cpwd != cpw1)
            {
                return AlertMsg("密码不一致！", Request.UrlReferrer.ToString());
            }
            var model = _AccountsInfoTask.GetByAccount(WebFormsAuthService.GetCurrentAccount());
            if (model == null)
            {
                return new EmptyResult();
            }
            if (model.Password != CryptTools.HashPassword(pwd))
                return AlertMsg("账号或密码不正确", Request.UrlReferrer.PathAndQuery);
            model.Password = CryptTools.HashPassword(cpwd);
            _AccountsInfoTask.Update(model);
            return AlertMsg("修改成功！", "/usercenter/changepwd");

        }

    }
}
